<template>
	<view>
		<view class="tab-list" :class="{between: align === 'between'}" >
			<view class="tab-item" v-for="(item, index) in tabList" :key="index" :class="{active: tabActiveIndex === index}"
				@tap="tabChange(index)">
					<view class="">
						<text>{{keyName ? item[keyName] : item}}</text>
						<text v-if="item.count && item.count > 0"> ({{item.count}})</text>
						<view class="underline" v-if="tabActiveIndex === index"></view>
					</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "Tabs",
		props: {
			tabList: {
				default: []
			},
			keyName: {
				default: ''
			},
			align: {
				default: 'center'
			}
			
		},
		data() {
			return {
				tabActiveIndex: 0
			}
		},
		methods: {
			tabChange(index) {
				this.tabActiveIndex = index
				this.$emit('tabChange', index)
			},
		}
	}
</script>

<style lang="scss">
	.tab-list {
		display: flex;
		justify-content: center;
		width: 100%;

		.tab-item {
			display: flex;
			justify-content: center;
			align-items: center;
			flex: 1;
			font-weight: 500;
			font-size: 28rpx;
			height: 44rpx;
			color: #808080;
			font-style: normal;
			text-transform: none;
			transition: font-size .1s;
			padding: 40rpx 0; 
		}

		.active {
			font-weight: bold;
			font-size: 31rpx;
			color: #333333;
			font-style: normal;
			text-transform: none;
		}
	}
	
	.between{
		justify-content: space-between;
		
		.tab-item{
			flex:none;
		}
	}
	
	.underline{
		position: relative;
		top: 10rpx;
		width: 40rpx;
		height: 6rpx;
		background: $theme-color;
		border-radius: 2rpx 2rpx 2rpx 2rpx;
		margin: auto;
	}
</style>